import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;

public class Filtro {
	public static void main(String args[]) {
		try {
			BufferedReader entrada = new BufferedReader(new FileReader(args[0]));
			FileOutputStream saida = new FileOutputStream(args[1]);
			String string;
			while ((string = entrada.readLine()) != null) {
				String[] palavras;
				if (string.contains(" ")) {
					palavras = string.split(" ");
				} else {
					palavras = new String[1];
					palavras[0] = string;
				}
				for (int i = 0; i < palavras.length; i++) {
					String palavra = palavras[i];
					if (ehReferencia(palavra)) {
						continue;
					} if (palavra.contains("entry-content")) {
						palavra = palavra.split(">")[1];
					} if (palavra.contains("</span>")) {
						palavra = palavra.split("<")[0];
					} if (palavra.contains("title=")) {
						palavra = palavra.replace("title=", "");
					}
					palavra = removeSinaisDePontuacao(palavra);
					if (ehValida(palavra)) {
						saida.write((palavra + System.getProperty("line.separator")).getBytes());
					}
				}
			}
			entrada.close();
			saida.close();
		} catch (Exception ex) {
			System.err.println(ex.getMessage());
	    }
	}
	
	private static boolean ehReferencia(String string) {
		return string.equals("<span") || string.contains("class=") || string.contains("rel=") || 
		string.contains("target=") || string.contains("href=") || string.contains("target=") ||
		string.contains("<a") || string.contains("username") || string.contains("web") || 
		string.contains("&amp") || string.contains("hashtag");
	}
	
	private static String removeSinaisDePontuacao(String string) {
		while (string.contains(".")) string = string.replace(".", "");
		string = string.replaceAll("!", "");
		string = string.replaceAll(",", "");
		string = string.replaceAll(";", "");
		string = string.replaceAll("#", "");
		string = string.replace("(", "");
		string = string.replace(")", "");
		string = string.replace("?", "");
		string = string.replace(":", "");
		string = string.replace("&quot", "");
		string = string.replace("'", "");
		return string;
	}
	
	private static boolean ehValida(String string) {
		return !string.isEmpty() && !string.contains("kkk") && !string.equals("+") && !string.equals("-")
		&& !string.equals("*") && !string.equals("(") && !string.equals(")") && !string.equalsIgnoreCase("a") 
		&& !string.equalsIgnoreCase("e") && !string.equalsIgnoreCase("e") && !string.equalsIgnoreCase("o") 
		&& !string.equalsIgnoreCase("u") && !string.equalsIgnoreCase("do") && !string.equalsIgnoreCase("da") 
		&& !string.equalsIgnoreCase("nao") && !string.equalsIgnoreCase("sim") && !string.equalsIgnoreCase("de")
		&& !string.equalsIgnoreCase("meu") && !string.equalsIgnoreCase("seu") && !string.equalsIgnoreCase("ele")
		&& !string.equalsIgnoreCase("ela") && !string.equalsIgnoreCase("teu") && !string.equalsIgnoreCase("nosso")
		&& !string.equalsIgnoreCase("voce") && !string.equalsIgnoreCase("que") && !string.equalsIgnoreCase("ah") 
		&& !string.equalsIgnoreCase("eu") && !string.equalsIgnoreCase("mais") && !string.equalsIgnoreCase("na")
		&& !string.equalsIgnoreCase("no") && !string.equalsIgnoreCase("por") && !string.equalsIgnoreCase("dos");
	}
}